using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The CourseTableManager class is responsible for managing BO.CourseTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class CourseTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all CourseTable objects in the database.
        /// </summary>
        /// <returns>A list with all CourseTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static CourseTableList GetList()
        {
            return CourseTableDB.GetList();
        }

        /// <summary>
        /// Custom (SchoolKey, StandardLevelKey)
        /// Gets a list with all CourseTable objects in the database.
        /// <param name="schoolKey">The schoolKey of the base table of CourseTable in the database.</param>
        /// <param name="standardLevelKey">The standardLevelKey base table of the CourseTable in the database.</param>
        /// </summary>
        /// <returns>A list with all CourseTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static CourseTableList GetList(int SchoolKey, int StandardLevelKey)
        {
            return CourseTableDB.GetList(SchoolKey, StandardLevelKey);
        }

        /// <summary>
        /// Gets a single CourseTable from the database without its data.
        /// </summary>
        /// <param name="courseKey">The CourseKey of the CourseTable in the database.</param>
        /// <returns>A CourseTable object when the CourseKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static CourseTable GetItem(int courseKey)
        {
            return GetItem(courseKey, false);
        }

        /// <summary>
        /// Gets a single CourseTable from the database.
        /// </summary>
        /// <param name="courseKey">The CourseKey of the CourseTable in the database.</param>
        /// <param name="getCourseTableRecords">Determines whether to load all associated CourseTable records as well.</param>
        /// <returns>
        /// A CourseTable object when the CourseKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static CourseTable GetItem(int courseKey, bool getCourseTableRecords)
        {
            CourseTable myCourseTable = CourseTableDB.GetItem(courseKey);
            //if (myCourseTable != null && getCourseTableRecords)
            //{
            //    myCourseTable.courseDetailTables = CourseDetailTableDB.GetListByCourseKey(courseKey);
            //}
            //if (myCourseTable != null && getCourseTableRecords)
            //{
            //    myCourseTable.educationPeriodStandardCourseTables = EducationPeriodStandardCourseTableDB.GetListByCourseKey(courseKey);
            //}
            return myCourseTable;
        }

        /// <summary>
        /// Saves a CourseTable in the database.
        /// </summary>
        /// <param name="myCourseTable">The CourseTable instance to save.</param>
        /// <returns>The new CourseKey if the CourseTable is new in the database or the existing CourseKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(CourseTable myCourseTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int courseTableCourseKey = CourseTableDB.Save(myCourseTable);
                //foreach (CourseDetailTable myCourseDetailTable in myCourseTable.courseDetailTables)
                //{
                //    myCourseDetailTable.CourseKey = courseTableCourseKey;
                //    CourseDetailTableDB.Save(myCourseDetailTable);
                //}
                //foreach (EducationPeriodStandardCourseTable myEducationPeriodStandardCourseTable in myCourseTable.educationPeriodStandardCourseTables)
                //{
                //    myEducationPeriodStandardCourseTable.CourseKey = courseTableCourseKey;
                //    EducationPeriodStandardCourseTableDB.Save(myEducationPeriodStandardCourseTable);
                //}

                //  Assign the CourseTable its new (or existing CourseKey).
                myCourseTable.CourseKey = courseTableCourseKey;

                myTransactionScope.Complete();

                return courseTableCourseKey;
            }
        }

        /// <summary>
        /// Deletes a CourseTable from the database.
        /// </summary>
        /// <param name="myCourseTable">The CourseTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(CourseTable myCourseTable)
        {
            return CourseTableDB.Delete(myCourseTable.CourseKey);
        }

        /// <summary>
        /// Deletes a CourseTable from the database.
        /// </summary>
        /// <param name="courseKey">The CourseKey of CourseTable to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public static bool Delete(int CourseKey)
        {
            return CourseTableDB.Delete(CourseKey);
        }

        #endregion

    }

}
